package framework.module.qrcodeAndBarCode.controller;

import com.google.zxing.WriterException;
import framework.common.ResponseVo;
import framework.util._BarcodeUtil;
import framework.util._QrcodeUtil;
import frameworkExt.util.controller.BaseControllerExt;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 条形码
 * @author 吴宇亮 on 2019/2/25 0025 17:39
 */
@Controller
@RequestMapping("/framework/module/Barcode.do")
public class BarcodeController extends BaseControllerExt {

    @RequestMapping(params = "method=generator")
    public void generator(HttpServletRequest request, HttpServletResponse response) {
        String barcodeMsg = request.getParameter("barcodeMsg");
        try {
            _BarcodeUtil.encoding(barcodeMsg, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(params = "method=parse")
    @ResponseBody
    public ResponseVo parse(@RequestParam(value="file") MultipartFile multmipartFile) {
        if (multmipartFile == null){
            return sendFail("文件为空，上传失败");
        }
        try {
            String decode = _BarcodeUtil.decode(multmipartFile.getInputStream());
            return sendSuccess(decode);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());
        }
    }
}
